package cyz.text.textactivity.core.handler;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

public class CyzMessageQueue {

    /**
     * 自己定义一个阻塞队列 为50
     */
    BlockingQueue<CyzMessage>  blockingQueue = new ArrayBlockingQueue<>(50);
    public CyzMessageQueue(boolean quitAllowed) {
    }

    private native static long nativeInit();

    public void enqueueMessage(CyzMessage message) {
        try {
            //存入消息
            blockingQueue.put(message);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }

    /**
     * 从消息队列中取出消息
     * @return
     */
    public CyzMessage next() {
        try {
            return blockingQueue.take();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return null;
    }
}
